package com.example.springbott.controller;

import com.example.springbott.aspactJ.OperationName;
import com.example.springbott.bean.BaseRespVo;
import com.example.springbott.bean.MarketBrand;
import com.example.springbott.bean.common.BasePageInfo;
import com.example.springbott.bean.common.CommonData;
import com.example.springbott.service.AdminBrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 品牌制造商
 *
 * @author silic xia
 * @since 2022/11/21 13:44
 */
@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {

    @Autowired
    AdminBrandService adminBrandService;

    /**
     * 展示list
     *
     * @param /page=1&limit=20&id=1046023&name=%E8%82%AF&sort=add_time&order=desc
     * @return {返回正确json}
     * {"errno":402,"errmsg":"参数值不对"}
     * @author silic xia
     * @since 2022/11/21 13:46
     */
    @RequiresPermissions("admin:brand:list")
    @RequestMapping("list")
    @OperationName("1")
    public BaseRespVo adminBrandList(BasePageInfo info, String id, String name) {
        BaseRespVo vo = null;
        if (id != null){
            CommonData<MarketBrand> data = null;
            try {
                data = adminBrandService.adminBrandList(info, Integer.valueOf(id), name);
            } catch (NumberFormatException e) {
                return vo = BaseRespVo.invalidParameter402("参数不对");
            }
            return vo = BaseRespVo.ok(data);
        }
        CommonData<MarketBrand> data = adminBrandService.adminBrandList(info, null, name);
        vo = BaseRespVo.ok(data);
        return vo;
    }

    /**
     * 品牌制造商/新建
     *
     * @param {"name":"000000八嘎耶鲁品牌商","desc":"快一点","floorPrice":"500", "picUrl":"http://182.92.235.201:8083/wx/storage/fetch/n50pm7y8p1r39d2bn21k.JPG"}
     * @return
     * @author silic xia
     * @since 2022/11/21 15:21
     */
    @RequiresPermissions("admin:brand:create")
    @RequestMapping("create")
    @OperationName("1")
    public BaseRespVo adminBrandCreate(@RequestBody MarketBrand marketBrand) {
        MarketBrand data = adminBrandService.adminBrandCreate(marketBrand);
        return BaseRespVo.ok(data);
    }

    /**
     *  品牌制造商/修改
     *
     * @param {"id":1046025,"name":"x","desc":"1111","picUrl":"","sortOrder":50,"floorPrice":1000,
     * "addTime":"2022-11-21 15:25:17","updateTime":"2022-11-21 15:25:17","deleted":false}
     * @return data:MarketBrand、errmsg: "成功" 、errno: 0
     * @author silic xia
     * @since 2022/11/21 15:22
     */
    @RequiresPermissions("admin:brand:update")
    @RequestMapping("update")
    @OperationName("1")
    public BaseRespVo adminBrandUpdate(@RequestBody MarketBrand marketBrand){
        MarketBrand data = adminBrandService.adminBrandUpdate(marketBrand);
        return BaseRespVo.ok(data);
    }

    /**
     * 品牌制造商/删除
     * @param {"id":1046025,"name":"x","desc":"1111","picUrl":"","sortOrder":50,"floorPrice":1000,"
     * addTime":"2022-11-21 15:25:17","updateTime":"2022-11-21 15:25:17","deleted":false}
     * @return {"errno":0,"errmsg":"成功"}
     * @author silic xia
     * @since 2022/11/21 15:23
     */
    @RequiresPermissions("admin:brand:delete")
    @RequestMapping("delete")
    @OperationName("1")
    public BaseRespVo adminBrandDelete(@RequestBody MarketBrand marketBrand){
        adminBrandService.adminBrandDelete(marketBrand);
        return BaseRespVo.ok();
    }
}

